package controller

import (
	"github.com/gin-gonic/gin"
	"go_code/gin-blog/service"
	"net/http"
)

func GetArticleByCategoryId(c *gin.Context) {
	categoryId := c.Query("category_id")
	articleRecordList, err := service.GetArticleByCategoryId(categoryId)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "views/500.html", nil)
	}
	categoryList, err := service.GetAllCategoryList()
	if err != nil {
		c.HTML(http.StatusInternalServerError, "views/500.html", nil)
		return
	}
	c.HTML(http.StatusOK, "views/index.html", gin.H{
		"article_list":  articleRecordList,
		"category_list": categoryList,
	})
}
